using Game.Core;
using Game.Main.Model;
using Game.Manager;
using SimpleJSON;

namespace Game.Component
{
	public class SpeakerItem : BaseItem
	{
		public int musicIndex;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			musicIndex = data.state;
			PlayMusic();
		}

		public override void QuicklyTouch(TouchEventData touchEventData)
		{
			base.QuicklyTouch(touchEventData);
			musicIndex++;
			PlayMusic();
		}

		private void PlayMusic()
		{
			if (base.itemData.dragSound != null)
			{
				if (musicIndex < 0 || musicIndex > base.itemData.dragSound.Length)
				{
					musicIndex = 0;
				}
				if (musicIndex < 1)
				{
					RemoveAudioPlayer();
					StopDragEffect();
				}
				else
				{
					PlayDragEffect();
					Singleton<AudioManager>.Instance.PlayAudio(base.itemData.dragSound[musicIndex - 1], true, GetAudioPlayer(false));
				}
			}
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = musicIndex;
		}
	}
}
